package com.yan.demo.loopdemo;

import java.util.Scanner;

public class LoopDemo1 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        if(n < 0){
            System.err.println("您输入的数据不合法！");
        }
        int remainder;
        // 定义一个字符串用于从后往前拼接
        String str = "";
        while (true) {
            remainder = n % 2; // 取余数
            str = remainder + str; //字符串拼接
            n = n / 2;  // 取商
            // 判断当n等于0的时候解除死循环
            if (n == 0){
                break;
            }
        }
        System.out.println("str = " + str);
    }
}
